package io.gitee.yth.design.pattern.test.core.pattern.behavioral.interpreter;

/**
 * @author yth
 * @since 2023-05-01-23:22
 */
public class NotExp implements BooleanExp {

    private final BooleanExp operand;

    public NotExp(BooleanExp operand) {
        this.operand = operand;
    }

    @Override
    public boolean evaluate(Context context) {
        return !operand.evaluate(context);
    }

    @Override
    public BooleanExp replace(String var, BooleanExp exp) {
        return new NotExp(operand.replace(var, exp));
    }

    @Override
    public BooleanExp copy() {
        return new NotExp(operand);
    }
}
